import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.Arrays;
import java.util.Comparator;

class Student implements Comparable<Student>{
    public int age;
    public String name;

    public Student(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name=" + name +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return this.age-o.age;
    }
}
//比较器 Comparator
class AgeComparator implements Comparator<Student> {



    @Override
    public int compare(Student o1, Student o2) {
        return o1.age-o2.age;
    }
}

class NameComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}

public class Test {
    public static void main(String[] args) {
        Student student1=new Student(20,"王");
        Student student2=new Student(18,"王1");
        AgeComparator ageComparator=new AgeComparator();
//
//       int ret= ageComparator.compare(student1,student2);
//        System.out.println(ret);
        NameComparator nameComparator=new NameComparator();
        System.out.println(nameComparator.compare(student1, student2));

//
//        if(ageComparator.compare(student1,student2)>0){
//
//        }
    }
    public static void main2(String[] args) {
        Student[] student=new Student[3];
        student[0] =new Student(18,"we2");
        student[1] =new Student(17,"we3");
        student[2] =new Student(16,"we4");
        AgeComparator ageComparator=new AgeComparator();

        Arrays.sort(student,ageComparator);
        System.out.println(Arrays.toString(student));



    }
    public static void main1(String[] args) {
        Student student1=new Student(20,"王");
        Student student2=new Student(18,"王");
        if(student1.compareTo(student2)>0){
            System.out.println("student1>student2");
        }else if (student1.compareTo(student2)<0){
            System.out.println("student1<student2");
        }else{
            System.out.println("student1=student2");

        }


    }

}
